library(ggsci)
library(ggplot2)
library(ggpubr)
library(DescTools)

setwd("E:/Articles/En cours/Metabolite/")
DF<-read.csv2("E:/Articles/En cours/Metabolite/Hemodynamics.csv")
CC<-read.csv2("E:/Articles/En cours/Metabolite/Cell culture.csv")

PAH<-DF[which(DF$Study=="PAH"),]
PAH$Group<-factor(PAH$Group,levels=c("Control","PAH"))

HTN<-DF[which(DF$Study=="HTN"),]
HTN$Group<-factor(HTN$Group,levels=c("Control","HTN"))

CHF<-DF[which(DF$Study=="CHF"),]
CHF$Group<-factor(CHF$Group,levels=c("Control","CHF"))


#############HTN##################


mod1<-lm(LVFS~Group,HTN)
summary(mod1)
mean(subset(HTN, Group == "Control")$LVFS,na.rm=TRUE)
sd(subset(HTN, Group == "Control")$LVFS,na.rm=TRUE)
mean(subset(HTN, Group == "HTN")$LVFS,na.rm=TRUE)
sd(subset(HTN, Group == "HTN")$LVFS,na.rm=TRUE)

mod2<-lm(HEART.WEIGHT~Group,HTN)
summary(mod2)
mean(subset(HTN, Group == "Control")$HEART.WEIGHT,na.rm=TRUE)
sd(subset(HTN, Group == "Control")$HEART.WEIGHT,na.rm=TRUE)
mean(subset(HTN, Group == "HTN")$HEART.WEIGHT,na.rm=TRUE)
sd(subset(HTN, Group == "HTN")$HEART.WEIGHT,na.rm=TRUE)

mod3<-lm(LV.WEIGHT~Group,HTN)
summary(mod3)
mod4<-lm(RV.WEIGHT~Group,HTN)
summary(mod4)

mod5<-lm(SBP~Group,HTN)
summary(mod5)
mean(subset(HTN, Group == "Control")$SBP,na.rm=TRUE)
sd(subset(HTN, Group == "Control")$SBP,na.rm=TRUE)
mean(subset(HTN, Group == "HTN")$SBP,na.rm=TRUE)
sd(subset(HTN, Group == "HTN")$SBP,na.rm=TRUE)

mod6<-lm(ALDO~Group,HTN)
summary(mod6)
mean(subset(HTN, Group == "Control")$ALDO,na.rm=TRUE)
sd(subset(HTN, Group == "Control")$ALDO,na.rm=TRUE)
mean(subset(HTN, Group == "HTN")$ALDO,na.rm=TRUE)
sd(subset(HTN, Group == "HTN")$ALDO,na.rm=TRUE)




p1a<-ggplot(data=subset(HTN, !is.na(LVFS)), aes(x = Group, y = LVFS)) +
  geom_boxplot(aes(fill = Group), alpha = 0.5,outlier.shape=NA)+xlab("")+ylab("LVFS %")+
  geom_jitter(size=1.4,aes(color = Group),show.legend=FALSE)+
  geom_segment(aes(x = 1, y = 58, xend = 2, yend = 58),size=0.8,show.legend=FALSE)+
  annotate(geom="text",label="p<0.001",x=1.5,y=59.2,size=6)+
  scale_fill_jco()+ # Boxplot fill color
  scale_color_jco()+ # Jitter color palette
  theme_classic()+ylim(20,60)+ theme(plot.title=element_text(hjust=0.5))+
  theme(legend.position = c(0.85, 0.93),axis.text=element_text(size=16),axis.title=element_text(size=16),axis.line = element_line(colour = 'black', size = 1.2),legend.title = element_text(size = 24),legend.text = element_text(size = 24))

p1b<-ggplot(data=subset(HTN, !is.na(HEART.WEIGHT)), aes(x = Group, y = HEART.WEIGHT)) +
  geom_boxplot(aes(fill = Group), alpha = 0.5,outlier.shape=NA)+xlab("")+ylab("Heart weight (g)")+
  geom_jitter(size=1.4,aes(color = Group),show.legend=FALSE)+
  geom_segment(aes(x = 1, y = 2.25, xend = 2, yend = 2.25),size=0.8,show.legend=FALSE)+
  annotate(geom="text",label="p=0.004",x=1.5,y=2.28,size=6)+
  scale_fill_jco()+ # Boxplot fill color
  scale_color_jco()+ # Jitter color palette
  theme_classic()+ylim(1.3,2.3)+ theme(plot.title=element_text(hjust=0.5))+
  theme(legend.position = c(0.85, 0.93),axis.text=element_text(size=16),axis.title=element_text(size=16),axis.line = element_line(colour = 'black', size = 1.2),legend.title = element_text(size = 24),legend.text = element_text(size = 24))

p1c<-ggplot(data=subset(HTN, !is.na(SBP)), aes(x = Group, y = SBP)) +
  geom_boxplot(aes(fill = Group), alpha = 0.5,outlier.shape=NA)+xlab("")+ylab("SBP (mm Hg)")+
  geom_jitter(size=1.4,aes(color = Group),show.legend=FALSE)+
  geom_segment(aes(x = 1, y = 195, xend = 2, yend = 195),size=0.8,show.legend=FALSE)+
  annotate(geom="text",label="p<0.001",x=1.5,y=198,size=6)+
  scale_fill_jco()+ # Boxplot fill color
  scale_color_jco()+ # Jitter color palette
  theme_classic()+ylim(100,200)+ theme(plot.title=element_text(hjust=0.5))+
  theme(legend.position = c(0.85, 0.93),axis.text=element_text(size=16),axis.title=element_text(size=16),axis.line = element_line(colour = 'black', size = 1.2),legend.title = element_text(size = 24),legend.text = element_text(size = 24))

p1d<-ggplot(data=subset(HTN, !is.na(ALDO)), aes(x = Group, y = ALDO)) +
  geom_boxplot(aes(fill = Group), alpha = 0.5,outlier.shape=NA)+xlab("")+ylab("Aldosterone (pM)")+
  geom_jitter(size=1.4,aes(color = Group),show.legend=FALSE)+
  geom_segment(aes(x = 1, y = 2380, xend = 2, yend = 2380),size=0.8,show.legend=FALSE)+
  annotate(geom="text",label="p=0.004",x=1.5,y=2452,size=6)+
  scale_fill_jco()+ # Boxplot fill color
  scale_color_jco()+ # Jitter color palette
  theme_classic()+ylim(100,2500)+ theme(plot.title=element_text(hjust=0.5))+
  theme(legend.position = c(0.85, 0.93),axis.text=element_text(size=16),axis.title=element_text(size=16),axis.line = element_line(colour = 'black', size = 1.2),legend.title = element_text(size = 24),legend.text = element_text(size = 24))

png(file = "Fig Hemo HTN.png", width = 12, height = 12, units = 'in',res=600)
ggarrange(p1d, p1c, p1a, p1b,labels = "AUTO",legend="right",common.legend=TRUE,font.label = list(size = 18, face = "bold"))
dev.off()

###SIMPLE LINEAR REGRESSION###
lapply(X = intersect(search(), objects()), 
FUN = function(X){detach(name = X, character.only = TRUE)})
covariates<-unlist(strsplit(names(HTN), split=" "))
predictors<-covariates[c(13:34)]

univ_formulas <- sapply(predictors,
                        function(x) as.formula(paste(x,"~Group")))
univ_models <- lapply(univ_formulas, function(x){glm(x, data = HTN,family=gaussian)})
univ_results <- lapply(univ_models,
                       function(x){ 
                          y <- summary(x)
                          p.value<-signif(summary(x)$coefficients[2,4], digits=3)
                          Beta<-signif(summary(x)$coefficients[2,1], digits=3)
                          Betase<-signif(summary(x)$coefficients[2,2], digits=3)
                          res2<-c(p.value,Beta,Betase)
                          names(res2)<-c("p-value","Beta","Betase")
			        return(res2)})    
res2 <- data.frame(t(as.data.frame(univ_results, check.names = FALSE)))
res2$adjP<-p.adjust(res2$p.value, method = "BH", n = length(res2$p.value))
res2 
write.csv2(res2,"StatsHTN.csv")

HTNCTRL <- subset(HTN, Group == "Control")
Quantile<-sapply(HTNCTRL[13:34], quantile)
MEDCTRLHTN<-data.frame(Quantile[3,],Quantile[2,],Quantile[4,])
colnames(MEDCTRLHTN)<-c("Median","First","Third")
HTNHTN <- subset(HTN, Group == "HTN")
Quantile<-sapply(HTNHTN[13:34], quantile)
MEDHTNHTN<-data.frame(Quantile[3,],Quantile[2,],Quantile[4,])
write.csv2(MEDCTRLHTN,"IQRCTRLHTN.csv")
write.csv2(MEDHTNHTN,"IQRHTNHTN.csv")


#############CHF##################

mod1<-lm(LVFS~Group,CHF)
summary(mod1)
mean(subset(CHF, Group == "Control")$LVFS)
sd(subset(CHF, Group == "Control")$LVFS)
mean(subset(CHF, Group == "CHF")$LVFS)
sd(subset(CHF, Group == "CHF")$LVFS)

mod2<-lm(CardiacOutput~Group,CHF)
summary(mod2)
mean(subset(CHF, Group == "Control")$CardiacOutput,na.rm=TRUE)
sd(subset(CHF, Group == "Control")$CardiacOutput,na.rm=TRUE)
mean(subset(CHF, Group == "CHF")$CardiacOutput,na.rm=TRUE)
sd(subset(CHF, Group == "CHF")$CardiacOutput,na.rm=TRUE)

mod3<-lm(HEART.WEIGHT~Group,CHF)
summary(mod3)
mean(subset(CHF, Group == "Control")$HEART.WEIGHT)
sd(subset(CHF, Group == "Control")$HEART.WEIGHT)
mean(subset(CHF, Group == "CHF")$HEART.WEIGHT)
sd(subset(CHF, Group == "CHF")$HEART.WEIGHT)

mod4<-lm(LV.WEIGHT~Group,CHF)
summary(mod4)
mean(subset(CHF, Group == "Control")$LV.WEIGHT)
sd(subset(CHF, Group == "Control")$LV.WEIGHT)
mean(subset(CHF, Group == "CHF")$LV.WEIGHT)
sd(subset(CHF, Group == "CHF")$LV.WEIGHT)

mod5<-lm(RV.WEIGHT~Group,CHF)
summary(mod5)
mean(subset(CHF, Group == "Control")$RV.WEIGHT)
sd(subset(CHF, Group == "Control")$RV.WEIGHT)
mean(subset(CHF, Group == "CHF")$RV.WEIGHT)
sd(subset(CHF, Group == "CHF")$RV.WEIGHT)

mod4<-lm(mPAP~Group,CHF)
summary(mod4)
mean(subset(CHF, Group == "Control")$mPAP)
sd(subset(CHF, Group == "Control")$mPAP)
mean(subset(CHF, Group == "CHF")$mPAP)
sd(subset(CHF, Group == "CHF")$mPAP)


p2a<-ggplot(data=subset(CHF, !is.na(LVFS)), aes(x = Group, y = LVFS)) +
  geom_boxplot(aes(fill = Group), alpha = 0.5,outlier.shape=NA)+xlab("")+ylab("LVFS %")+
  geom_jitter(size=1.4,aes(color = Group),show.legend=FALSE)+
  geom_segment(aes(x = 1, y = 67.25, xend = 2, yend = 67.25),size=0.8,show.legend=FALSE)+
  annotate(geom="text",label="p<0.001",x=1.5,y=68.9,size=6)+
  scale_fill_jco()+ # Boxplot fill color
  scale_color_jco()+ # Jitter color palette
  theme_classic()+ylim(15,70)+ theme(plot.title=element_text(hjust=0.5))+
  theme(legend.position = c(0.85, 0.93),axis.text=element_text(size=16),axis.title=element_text(size=16),axis.line = element_line(colour = 'black', size = 1.2),legend.title = element_text(size = 24),legend.text = element_text(size = 24))

p2b<-ggplot(data=subset(CHF, !is.na(HEART.WEIGHT)), aes(x = Group, y = HEART.WEIGHT)) +
  geom_boxplot(aes(fill = Group), alpha = 0.5,outlier.shape=NA)+xlab("")+ylab("Heart weight (g)")+
  geom_jitter(size=1.4,aes(color = Group),show.legend=FALSE)+
  geom_segment(aes(x = 1, y = 2.06, xend = 2, yend = 2.06),size=0.8,show.legend=FALSE)+
  annotate(geom="text",label="p=0.008",x=1.45,y=2.084,size=6)+
  scale_fill_jco()+ # Boxplot fill color
  scale_color_jco()+ # Jitter color palette
  theme_classic()+ylim(1.3,2.1)+ theme(plot.title=element_text(hjust=0.5))+
  theme(legend.position = c(0.85, 0.93),axis.text=element_text(size=16),axis.title=element_text(size=16),axis.line = element_line(colour = 'black', size = 1.2),legend.title = element_text(size = 24),legend.text = element_text(size = 24))


p2c<-ggplot(data=subset(CHF, !is.na(LV.WEIGHT)), aes(x = Group, y = LV.WEIGHT)) +
  geom_boxplot(aes(fill = Group), alpha = 0.5,outlier.shape=NA)+xlab("")+ylab("Left ventricle weight (g)")+
  geom_jitter(size=1.4,aes(color = Group),show.legend=FALSE)+
  geom_segment(aes(x = 1, y = 1.665, xend = 2, yend = 1.665),size=0.8,show.legend=FALSE)+
  annotate(geom="text",label="p=0.016",x=1.5,y=1.686,size=6)+
  scale_fill_jco()+ # Boxplot fill color
  scale_color_jco()+ # Jitter color palette
  theme_classic()+ylim(1,1.7)+ theme(plot.title=element_text(hjust=0.5))+
  theme(legend.position = c(0.85, 0.93),axis.text=element_text(size=16),axis.title=element_text(size=16),axis.line = element_line(colour = 'black', size = 1.2),legend.title = element_text(size = 24),legend.text = element_text(size = 24))

p2d<-ggplot(data=subset(CHF, !is.na(RV.WEIGHT)), aes(x = Group, y = RV.WEIGHT)) +
  geom_boxplot(aes(fill = Group), alpha = 0.5,outlier.shape=NA)+xlab("")+ylab("Right Ventricle weight (g)")+
  geom_jitter(size=1.4,aes(color = Group),show.legend=FALSE)+
  geom_segment(aes(x = 1, y =.48, xend = 2, yend = .48),size=0.8,show.legend=FALSE)+
  annotate(geom="text",label="p=0.009",x=1.5,y=.492,size=6)+
  scale_fill_jco()+ # Boxplot fill color
  scale_color_jco()+ # Jitter color palette
  theme_classic()+ylim(.1,0.5)+ theme(plot.title=element_text(hjust=0.5))+
  theme(legend.position = c(0.85, 0.93),axis.text=element_text(size=16),axis.title=element_text(size=16),axis.line = element_line(colour = 'black', size = 1.2),legend.title = element_text(size = 24),legend.text = element_text(size = 24))


png(file = "Fig Hemo CHF.png", width = 12, height = 12, units = 'in',res=600)
ggarrange(p2a, p2b,p2c, p2d,labels = "AUTO",legend="right",common.legend=TRUE,font.label = list(size = 18, face = "bold"))
dev.off()

###SIMPLE LINEAR REGRESSION###
lapply(X = intersect(search(), objects()), 
FUN = function(X){detach(name = X, character.only = TRUE)})
covariates<-unlist(strsplit(names(CHF), split=" "))
predictors<-covariates[c(13:34)]

univ_formulas <- sapply(predictors,
                        function(x) as.formula(paste(x,"~Group")))
univ_models <- lapply(univ_formulas, function(x){glm(x, data = CHF,family=gaussian)})
univ_results <- lapply(univ_models,
                       function(x){ 
                          y <- summary(x)
                          p.value<-signif(summary(x)$coefficients[2,4], digits=3)
                          Beta<-signif(summary(x)$coefficients[2,1], digits=3)
                          Betase<-signif(summary(x)$coefficients[2,2], digits=3)
                          res2<-c(p.value,Beta,Betase)
                          names(res2)<-c("p-value","Beta","Betase")
			        return(res2)})    
res2 <- data.frame(t(as.data.frame(univ_results, check.names = FALSE)))
res2$adjP<-p.adjust(res2$p.value, method = "BH", n = length(res2$p.value))
res2 
write.csv2(res2,"StatsCHF.csv")

CHFCTRL <- subset(CHF, Group == "Control")
Quantile<-sapply(CHFCTRL[13:34], quantile)
MEDCTRLCHF<-data.frame(Quantile[3,],Quantile[2,],Quantile[4,])
colnames(MEDCTRLCHF)<-c("Median","First","Third")
CHFCHF<- subset(CHF, Group == "CHF")
Quantile<-sapply(CHFCHF[13:34], quantile)
MEDCHFCHF<-data.frame(Quantile[3,],Quantile[2,],Quantile[4,])
write.csv2(MEDCTRLCHF,"IQRCTRLCHF.csv")
write.csv2(MEDCHFCHF,"IQRCHFCHF.csv")


#############PAH##################

mod1<-lm(CardiacOutput~Group,PAH)
summary(mod1)
mean(subset(PAH, Group == "Control")$CardiacOutput,na.rm=TRUE)
sd(subset(PAH, Group == "Control")$CardiacOutput,na.rm=TRUE)
mean(subset(PAH, Group == "PAH")$CardiacOutput,na.rm=TRUE)
sd(subset(PAH, Group == "PAH")$CardiacOutput,na.rm=TRUE)

mod2<-lm(HEART.WEIGHT~Group,PAH)
summary(mod2)
mean(subset(PAH, Group == "Control")$HEART.WEIGHT,na.rm=TRUE)
sd(subset(PAH, Group == "Control")$HEART.WEIGHT,na.rm=TRUE)
mean(subset(PAH, Group == "PAH")$HEART.WEIGHT,na.rm=TRUE)
sd(subset(PAH, Group == "PAH")$HEART.WEIGHT,na.rm=TRUE)

mod3<-lm(LV.WEIGHT~Group,PAH)
summary(mod3)
mean(subset(PAH, Group == "Control")$LV.WEIGHT,na.rm=TRUE)
sd(subset(PAH, Group == "Control")$LV.WEIGHT,na.rm=TRUE)
mean(subset(PAH, Group == "PAH")$LV.WEIGHT,na.rm=TRUE)
sd(subset(PAH, Group == "PAH")$LV.WEIGHT,na.rm=TRUE)

mod4<-lm(RV.WEIGHT~Group,PAH)
summary(mod4)
mean(subset(PAH, Group == "Control")$RV.WEIGHT,na.rm=TRUE)
sd(subset(PAH, Group == "Control")$RV.WEIGHT,na.rm=TRUE)
mean(subset(PAH, Group == "PAH")$RV.WEIGHT,na.rm=TRUE)
sd(subset(PAH, Group == "PAH")$RV.WEIGHT,na.rm=TRUE)

mod5<-lm(mPAP~Group,PAH)
summary(mod5)
mean(subset(PAH, Group == "Control")$mPAP,na.rm=TRUE)
sd(subset(PAH, Group == "Control")$mPAP,na.rm=TRUE)
mean(subset(PAH, Group == "PAH")$mPAP,na.rm=TRUE)
sd(subset(PAH, Group == "PAH")$mPAP,na.rm=TRUE)


p3a<-ggplot(data=subset(PAH, !is.na(mPAP)), aes(x = Group, y = mPAP)) +
  geom_boxplot(aes(fill = Group), alpha = 0.5,outlier.shape=NA)+xlab("")+ylab("mPAP (mm Hg)")+
  geom_jitter(size=1.4,aes(color = Group),show.legend=FALSE)+
  geom_segment(aes(x = 1, y = 67, xend = 2, yend = 67),size=0.8,show.legend=FALSE)+
  annotate(geom="text",label="p<0.001",x=1.5,y=68.8,size=6)+
  scale_fill_jco()+ # Boxplot fill color
  scale_color_jco()+ # Jitter color palette
  theme_classic()+ylim(10,70)+ theme(plot.title=element_text(hjust=0.5))+
  theme(legend.position = c(0.85, 0.93),axis.text=element_text(size=16),axis.title=element_text(size=16),axis.line = element_line(colour = 'black', size = 1.2),legend.title = element_text(size = 24),legend.text = element_text(size = 24))

p3b<-ggplot(data=subset(PAH, !is.na(HEART.WEIGHT)), aes(x = Group, y = HEART.WEIGHT)) +
  geom_boxplot(aes(fill = Group), alpha = 0.5,outlier.shape=NA)+xlab("")+ylab("Heart weight (g)")+
  geom_jitter(size=1.4,aes(color = Group),show.legend=FALSE)+
  geom_segment(aes(x = 1, y = 2.9075, xend = 2, yend = 2.9075),size=0.8,show.legend=FALSE)+
  annotate(geom="text",label="p<0.001",x=1.45,y=2.963,size=6)+
  scale_fill_jco()+ # Boxplot fill color
  scale_color_jco()+ # Jitter color palette
  theme_classic()+ylim(1.15,3)+ theme(plot.title=element_text(hjust=0.5))+
  theme(legend.position = c(0.85, 0.93),axis.text=element_text(size=16),axis.title=element_text(size=16),axis.line = element_line(colour = 'black', size = 1.2),legend.title = element_text(size = 24),legend.text = element_text(size = 24))


p3c<-ggplot(data=subset(PAH, !is.na(LV.WEIGHT)), aes(x = Group, y = LV.WEIGHT)) +
  geom_boxplot(aes(fill = Group), alpha = 0.5,outlier.shape=NA)+xlab("")+ylab("Left ventricle weight (g)")+
  geom_jitter(size=1.4,aes(color = Group),show.legend=FALSE)+
  geom_segment(aes(x = 1, y = 1.84, xend = 2, yend = 1.84),size=0.8,show.legend=FALSE)+
  annotate(geom="text",label="p=<0.001",x=1.5,y=1.876,size=6)+
  scale_fill_jco()+ # Boxplot fill color
  scale_color_jco()+ # Jitter color palette
  theme_classic()+ylim(0.7,1.9)+ theme(plot.title=element_text(hjust=0.5))+
  theme(legend.position = c(0.85, 0.93),axis.text=element_text(size=16),axis.title=element_text(size=16),axis.line = element_line(colour = 'black', size = 1.2),legend.title = element_text(size = 24),legend.text = element_text(size = 24))

p3d<-ggplot(data=subset(PAH, !is.na(RV.WEIGHT)), aes(x = Group, y = RV.WEIGHT)) +
  geom_boxplot(aes(fill = Group), alpha = 0.5,outlier.shape=NA)+xlab("")+ylab("Right ventricle weight (g)")+
  geom_jitter(size=1.4,aes(color = Group),show.legend=FALSE)+
  geom_segment(aes(x = 1, y =.48, xend = 2, yend = .48),size=0.8,show.legend=FALSE)+
  annotate(geom="text",label="p<0.001",x=1.5,y=.492,size=6)+
  scale_fill_jco()+ # Boxplot fill color
  scale_color_jco()+ # Jitter color palette
  theme_classic()+ylim(.1,0.5)+ theme(plot.title=element_text(hjust=0.5))+
  theme(legend.position = c(0.85, 0.93),axis.text=element_text(size=16),axis.title=element_text(size=16),axis.line = element_line(colour = 'black', size = 1.2),legend.title = element_text(size = 24),legend.text = element_text(size = 24))


p3e<-ggplot(data=subset(PAH, !is.na(CardiacOutput)), aes(x = Group, y = CardiacOutput)) +
  geom_boxplot(aes(fill = Group), alpha = 0.5,outlier.shape=NA)+xlab("")+ylab("Cardiac output (ml/min)")+
  geom_jitter(size=1.4,aes(color = Group),show.legend=FALSE)+
  geom_segment(aes(x = 1, y =116, xend = 2, yend = 116),size=0.8,show.legend=FALSE)+
  annotate(geom="text",label="p<0.001",x=1.5,y=118.4,size=6)+
  scale_fill_jco()+ # Boxplot fill color
  scale_color_jco()+ # Jitter color palette
  theme_classic()+ylim(40,120)+ theme(plot.title=element_text(hjust=0.5))+
  theme(legend.position = c(0.85, 0.93),axis.text=element_text(size=16),axis.title=element_text(size=16),axis.line = element_line(colour = 'black', size = 1.2),legend.title = element_text(size = 24),legend.text = element_text(size = 24))


png(file = "Hemo PAH.png", width = 12, height = 18, units = 'in',res=600)
ggarrange(p3a, p3b,p3c,p3d,p3e,ncol=2,nrow=3,labels = "AUTO",legend="right",common.legend=TRUE,font.label = list(size = 18, face = "bold"))
dev.off()

###SIMPLE LINEAR REGRESSION###
lapply(X = intersect(search(), objects()), 
FUN = function(X){detach(name = X, character.only = TRUE)})
covariates<-unlist(strsplit(names(PAH), split=" "))
predictors<-covariates[c(13:34)]

univ_formulas <- sapply(predictors,
                        function(x) as.formula(paste(x,"~Group")))
univ_models <- lapply(univ_formulas, function(x){glm(x, data = PAH,family=gaussian)})
univ_results <- lapply(univ_models,
                       function(x){ 
                          y <- summary(x)
                          p.value<-signif(summary(x)$coefficients[2,4], digits=3)
                          Beta<-signif(summary(x)$coefficients[2,1], digits=3)
                          Betase<-signif(summary(x)$coefficients[2,2], digits=3)
                          res2<-c(p.value,Beta,Betase)
                          names(res2)<-c("p-value","Beta","Betase")
			        return(res2)})    
res2 <- data.frame(t(as.data.frame(univ_results, check.names = FALSE)))
res2$adjP<-p.adjust(res2$p.value, method = "BH", n = length(res2$p.value))
res2 
write.csv2(res2,"StatsPAH.csv")

PAHCTRL <- subset(PAH, Group == "Control")
Quantile<-sapply(PAHCTRL[13:34], quantile)
MEDCTRLPAH<-data.frame(Quantile[3,],Quantile[2,],Quantile[4,])
colnames(MEDCTRLPAH)<-c("Median","First","Third")
PAHPAH<- subset(PAH, Group == "PAH")
Quantile<-sapply(PAHPAH[13:34], quantile)
MEDPAHPAH<-data.frame(Quantile[3,],Quantile[2,],Quantile[4,])
write.csv2(MEDCTRLPAH,"IQRCTRLPAH.csv")
write.csv2(MEDPAHPAH,"IQRPAHPAH.csv")


p4a<-ggplot(data=subset(PAH, !is.na(LPA.16.0.)), aes(x = Group, y = LPA.16.0.)) +
  geom_boxplot(aes(fill = Group), alpha = 0.5,outlier.shape=NA)+xlab("")+ylab("LPA(16:0)")+
  geom_jitter(size=1.4,aes(color = Group),show.legend=FALSE)+
  geom_segment(aes(x = 1, y = 0.4775, xend = 2, yend = 0.4775),size=0.8,show.legend=FALSE)+
  annotate(geom="text",label="p=0.003",x=1.5,y=0.4910,size=6)+
  scale_fill_jco()+ # Boxplot fill color
  scale_color_jco()+ # Jitter color palette
  theme_classic()+ylim(0.05,0.5)+ theme(plot.title=element_text(hjust=0.5))+
  theme(legend.position = c(0.85, 0.93),axis.text=element_text(size=16),axis.title=element_text(size=16),axis.line = element_line(colour = 'black', size = 1.2),legend.title = element_text(size = 24),legend.text = element_text(size = 24))

p4b<-ggplot(data=subset(PAH, !is.na(LPA.18.0.)), aes(x = Group, y = LPA.18.0.)) +
  geom_boxplot(aes(fill = Group), alpha = 0.5,outlier.shape=NA)+xlab("")+ylab("LPA(18:0)")+
  geom_jitter(size=1.4,aes(color = Group),show.legend=FALSE)+
  geom_segment(aes(x = 1, y = 0.3175, xend = 2, yend = 0.3175),size=0.8,show.legend=FALSE)+
  annotate(geom="text",label="p=0.219",x=1.5,y=0.325,size=6)+
  scale_fill_jco()+ # Boxplot fill color
  scale_color_jco()+ # Jitter color palette
  theme_classic()+ylim(0.08,0.33)+ theme(plot.title=element_text(hjust=0.5))+
  theme(legend.position = c(0.85, 0.93),axis.text=element_text(size=16),axis.title=element_text(size=16),axis.line = element_line(colour = 'black', size = 1.2),legend.title = element_text(size = 24),legend.text = element_text(size = 24))

p4c<-ggplot(data=subset(PAH, !is.na(LPA.18.1.)), aes(x = Group, y = LPA.18.1.)) +
  geom_boxplot(aes(fill = Group), alpha = 0.5,outlier.shape=NA)+xlab("")+ylab("LPA(18:1)")+
  geom_jitter(size=1.4,aes(color = Group),show.legend=FALSE)+
  geom_segment(aes(x = 1, y = 0.2865, xend = 2, yend = 0.2865),size=0.8,show.legend=FALSE)+
  annotate(geom="text",label="p=0.001",x=1.5,y=0.2946,size=6)+
  scale_fill_jco()+ # Boxplot fill color
  scale_color_jco()+ # Jitter color palette
  theme_classic()+ylim(0.03,0.3)+ theme(plot.title=element_text(hjust=0.5))+
  theme(legend.position = c(0.85, 0.93),axis.text=element_text(size=16),axis.title=element_text(size=16),axis.line = element_line(colour = 'black', size = 1.2),legend.title = element_text(size = 24),legend.text = element_text(size = 24))

p4d<-ggplot(data=subset(PAH, !is.na(LPA.18.2.)), aes(x = Group, y = LPA.18.2.)) +
  geom_boxplot(aes(fill = Group), alpha = 0.5,outlier.shape=NA)+xlab("")+ylab("LPA(18:2)")+
  geom_jitter(size=1.4,aes(color = Group),show.legend=FALSE)+
  geom_segment(aes(x = 1, y =4.775, xend = 2, yend = 4.775),size=0.8,show.legend=FALSE)+
  annotate(geom="text",label="p=0.001",x=1.5,y=4.91,size=6)+
  scale_fill_jco()+ # Boxplot fill color
  scale_color_jco()+ # Jitter color palette
  theme_classic()+ylim(0.5,5)+ theme(plot.title=element_text(hjust=0.5))+
  theme(legend.position = c(0.85, 0.93),axis.text=element_text(size=16),axis.title=element_text(size=16),axis.line = element_line(colour = 'black', size = 1.2),legend.title = element_text(size = 24),legend.text = element_text(size = 24))

p4e<-ggplot(data=subset(PAH, !is.na(LPA.20.4.)), aes(x = Group, y = LPA.20.4.)) +
  geom_boxplot(aes(fill = Group), alpha = 0.5,outlier.shape=NA)+xlab("")+ylab("LPA(20:4)")+
  geom_jitter(size=1.4,aes(color = Group),show.legend=FALSE)+
  geom_segment(aes(x = 1, y =3.37, xend = 2, yend = 3.37),size=0.8,show.legend=FALSE)+
  annotate(geom="text",label="p=0.004",x=1.5,y=3.448,size=6)+
  scale_fill_jco()+ # Boxplot fill color
  scale_color_jco()+ # Jitter color palette
  theme_classic()+ylim(0.9,3.5)+ theme(plot.title=element_text(hjust=0.5))+
  theme(legend.position = c(0.85, 0.93),axis.text=element_text(size=16),axis.title=element_text(size=16),axis.line = element_line(colour = 'black', size = 1.2),legend.title = element_text(size = 24),legend.text = element_text(size = 24))


p4f<-ggplot(data=subset(PAH, !is.na(LPA.22.6.)), aes(x = Group, y = LPA.22.6.)) +
  geom_boxplot(aes(fill = Group), alpha = 0.5,outlier.shape=NA)+xlab("")+ylab("LPA(22:6)")+
  geom_jitter(size=1.4,aes(color = Group),show.legend=FALSE)+
  geom_segment(aes(x = 1, y =0.239, xend = 2, yend = 0.239),size=0.8,show.legend=FALSE)+
  annotate(geom="text",label="p<0.001",x=1.5,y=0.2456,size=6)+
  scale_fill_jco()+ # Boxplot fill color
  scale_color_jco()+ # Jitter color palette
  theme_classic()+ylim(0.03,0.25)+ theme(plot.title=element_text(hjust=0.5))+
  theme(legend.position = c(0.85, 0.93),axis.text=element_text(size=16),axis.title=element_text(size=16),axis.line = element_line(colour = 'black', size = 1.2),legend.title = element_text(size = 24),legend.text = element_text(size = 24))


png(file = "LPA PAH.png", width = 12, height = 18, units = 'in',res=600)
ggarrange(p4a, p4b,p4c,p4d,p4e,p4f,ncol=2,nrow=3,labels = "AUTO",legend="right",common.legend=TRUE,font.label = list(size = 18, face = "bold"))
dev.off()


######## Cell Culture ###########
mod1<-lm(BrdU~Group,CC)
summary(mod1)
anova(mod1)
DunnettTest(x=CC$BrdU, g=CC$Group)

mean(subset(CC, Group == "Control")$BrdU,na.rm=TRUE)
sd(subset(CC, Group == "Control")$BrdU,na.rm=TRUE)
mean(subset(CC, Group == "LPA(18:1)")$BrdU,na.rm=TRUE)
sd(subset(CC, Group == "LPA(18:1)")$BrdU,na.rm=TRUE)
mean(subset(CC, Group == "LPA(18:2)")$BrdU,na.rm=TRUE)
sd(subset(CC, Group == "LPA(18:2)")$BrdU,na.rm=TRUE)
mean(subset(CC, Group == "LPA(20:4)")$BrdU,na.rm=TRUE)
sd(subset(CC, Group == "LPA(20:4)")$BrdU,na.rm=TRUE)

p5a<-ggplot(data=subset(CC, !is.na(BrdU)), aes(x = Group, y = BrdU)) +
  geom_boxplot(aes(fill = Group), alpha = 0.5,outlier.shape=NA)+xlab("")+ylab("% BrdU incorporation (Fold increased)")+
  geom_jitter(size=1.4,aes(color = Group),show.legend=FALSE)+
  geom_segment(aes(x = 1, y =1.94, xend = 4, yend = 1.94),size=0.8,show.legend=FALSE)+
  annotate(geom="text",label="p=0.001",x=2.5,y=1.976,size=6)+
  geom_segment(aes(x = 1, y =1.75, xend = 3, yend = 1.75),size=0.8,show.legend=FALSE)+
  annotate(geom="text",label="p=0.030",x=2,y=1.78,size=6)+
  geom_segment(aes(x = 1, y =1.56, xend = 2, yend = 1.56),size=0.8,show.legend=FALSE)+
  annotate(geom="text",label="p=0.021",x=1.5,y=1.584,size=6)+
  scale_fill_jco()+ # Boxplot fill color
  scale_color_jco()+ # Jitter color palette
  theme_classic()+ylim(0.8,2)+ theme(plot.title=element_text(hjust=0.5))+
  theme(legend.position = c(0.85, 0.93),axis.text=element_text(size=20),axis.title=element_text(size=20),axis.line = element_line(colour = 'black', size = 1.2),legend.title = element_text(size = 24),legend.text = element_text(size = 24))

png(file = "CC BrdU LPA.png", width = 12, height = 12, units = 'in',res=600)
ggarrange(p5a,ncol=1,nrow=1,legend="right",common.legend=TRUE,font.label = list(size = 18, face = "bold"))
dev.off()

